package com.mipo.client.javase.company.flytek.jinzhou.openapi;

import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

/*
 * edc-open-api:
 * 	client_id: cba0d5243a9d4a7daea0c8f594752f02
 * 	client_secret: ef1821da260537e5175c22f4d3a423a1
 * desk-top:
 * 	client_id: 4d3d3d741c524a38aab4845280040f43
 * 	client_secret: bde9a1723d3c3158adcc97dde7413403
 * thrid-party:
 * 	client_id: d37574cc34454ff1afd4870f82d7baa6
 * 	client_secret: 2c6e6e7a62379ff593140a372ad645a0
 */
public class ThirdPartyTestMain {
	public static void main(String[] args) throws Exception {
		// 获取token,8756edbe-5d11-432b-a958-d75e7915d0aa
		String url1 = "http://open.jztest.changyan.cn/authorization-token-server/oauth/token?client_id=cba0d5243a9d4a7daea0c8f594752f02&client_secret=ef1821da260537e5175c22f4d3a423a1&grant_type=client_credentials";
		//dslx.user.validate
		String url2 = "http://open.jztest.changyan.cn/api?method=dslx.user.validate&format=json&version=1.0&appkey=d37574cc34454ff1afd4870f82d7baa6&access_token=8756edbe-5d11-432b-a958-d75e7915d0aa&loginName=944f97d72b74123c5d02ebf068940dbd=&password=fc629c4fc9f9cc05";
		//dslx.resource.phase.get
		String url3 = "http://open.jztest.changyan.cn/api?method=dslx.resource.phase.get&format=json&version=1.0&appkey=cba0d5243a9d4a7daea0c8f594752f02&access_token=bc4d7ab3-a6ef-4f45-b5c7-56e4d26490c9";
		//dslx.resource.subject.get
		String url4 = "http://open.jztest.changyan.cn/api?method=dslx.resource.subject.get&format=json&version=1.0&appkey=d37574cc34454ff1afd4870f82d7baa6&access_token=8756edbe-5d11-432b-a958-d75e7915d0aa";
		//dslx.resource.meadiatype.get
		String url5 = "http://open.jztest.changyan.cn/api?method=dslx.resource.meadiatype.get&format=json&version=1.0&appkey=d37574cc34454ff1afd4870f82d7baa6&access_token=8756edbe-5d11-432b-a958-d75e7915d0aa";
		//dslx.resource.type.get
		String url6 = "http://open.jztest.changyan.cn/api?method=dslx.resource.type.get&format=json&version=1.0&appkey=d37574cc34454ff1afd4870f82d7baa6&access_token=8756edbe-5d11-432b-a958-d75e7915d0aa";
		//dslx.resource.publisher.get
		String url7 = "http://open.jztest.changyan.cn/api?method=dslx.resource.publisher.get&format=json&version=1.0&appkey=d37574cc34454ff1afd4870f82d7baa6&access_token=8756edbe-5d11-432b-a958-d75e7915d0aa&phase=03&subject=01";
		//dslx.resource.book.get
		String url8 = "http://open.jztest.changyan.cn/api?method=dslx.resource.book.get&format=json&version=1.0&appkey=d37574cc34454ff1afd4870f82d7baa6&access_token=8756edbe-5d11-432b-a958-d75e7915d0aa&phase=03&subject=01&publisher=01";
		//dslx.resource.unit.get
		String url9 = "http://open.jztest.changyan.cn/api?method=dslx.resource.unit.get&format=json&version=1.0&appkey=d37574cc34454ff1afd4870f82d7baa6&access_token=8756edbe-5d11-432b-a958-d75e7915d0aa&book=03010101-001";
		//dslx.resource.list
		String url10 = "http://open.jztest.changyan.cn/api?method=dslx.resource.list&format=json&version=1.0&appkey=d37574cc34454ff1afd4870f82d7baa6&access_token=8756edbe-5d11-432b-a958-d75e7915d0aa&phase=03&subject=01&publisher=01&book=03010101-001&unit1=&unit2=&unit3=&unit4=&quality=&sortField=uploadTime&page=1&limit=5&type=&keywords=&mediaType=&source=0";
		//dslx.pan.file.list
		String url11 = "http://open.jztest.changyan.cn/api?method=dslx.pan.file.list&format=json&version=1.0&appkey=cba0d5243a9d4a7daea0c8f594752f02&access_token=a961233b-32ce-45f7-89e3-df4486602f34&openId=91b85d128dd2286e52561cc5563482df51b7305609896019327d4606d95bf048b61c98f46e82b25ab4bb053f029c83a7440949d2f1487521&dirId=0&coverDir=true&coverFile=true&page=1&limit=10&order=3&source=0";
		//dslx.pan.file.prepare
		String url12 = "http://open.jztest.changyan.cn/api?version=1.0&format=json&appkey=cba0d5243a9d4a7daea0c8f594752f02&access_token=a961233b-32ce-45f7-89e3-df4486602f34&method=dslx.pan.file.prepare&fileName=PHP%E5%9F%BA%E7%A1%80%E5%9F%B9%E8%AE%AD.pptx";
		//cystorage files/upload
		String url13 = "http://cystorage.jztest.changyan.cn/v2/files/upload";
		//dslx.pan.file.uploadafter
		String url14 = "http://open.jztest.changyan.cn/api?version=1.0&format=json&appkey=cba0d5243a9d4a7daea0c8f594752f02&access_token=bc4d7ab3-a6ef-4f45-b5c7-56e4d26490c9&method=dslx.pan.file.uploadafter&openId=91b85d128dd2286e52561cc5563482df51b7305609896019327d4606d95bf048b61c98f46e82b25ab4bb053f029c83a7440949d2f1487521&contextId=5a9e5dd78436237d071d963a&status=2&length=373185&md5=ssssssbb8cb1d09056fb5c6ececf41a9485978&filename=%E4%BD%A0%E5%A5%BD.jpg&url=http%3A%2F%2Ftest.download.cycore.cn%2Frrt_jinzhou%2F2018%2F03%2F06%2F17%2Ffa45f21e-0aa7-4b9a-99d8-1e74785cd28b.pptx";
		//dslx.pan.file.delete
		String url15 = "http://open.jztest.changyan.cn/api?method=dslx.pan.file.delete&format=json&version=1.0&appkey=cba0d5243a9d4a7daea0c8f594752f02&access_token=0ac03b96-85f3-4043-944c-2943e54bacf6&fileId=a673602d-0214-439c-9bc2-d53c103955e6&openId=91b85d128dd2286e52561cc5563482df51b7305609896019327d4606d95bf048b61c98f46e82b25ab4bb053f029c83a7440949d2f1487521";
		//dslx.pan.file.download
		String url16 = "http://open.jztest.changyan.cn/api?method=dslx.pan.file.download&format=json&version=1.0&appkey=cba0d5243a9d4a7daea0c8f594752f02&access_token=0ac03b96-85f3-4043-944c-2943e54bacf6&fileId=a673602d-0214-439c-9bc2-d53c103955e6&openId=91b85d128dd2286e52561cc5563482df51b7305609896019327d4606d95bf048b61c98f46e82b25ab4bb053f029c83a7440949d2f1487521";
		
		excuteGetRequest(url3);
	}
	
	public static void excuteGetRequest(String url) throws Exception {
		CloseableHttpClient httpClient = HttpClients.createDefault();
		HttpGet httpGet = new HttpGet(url);
		CloseableHttpResponse response = httpClient.execute(httpGet); // 4.3版本不设置超时的话，一旦服务器没有响应，等待时间N久(>24小时)。
		HttpEntity entity = response.getEntity(); // 返回报文实体
		StatusLine status = response.getStatusLine();
		System.out.println("返回的状态码为：" + status); // 具体返回码(200)为status.getStatusCode(); 
		String ret = EntityUtils.toString(entity); // 将返回报文实体转换为字符串
		System.out.println("返回的报文为：" + ret);
		EntityUtils.consume(entity);  // 释放是否可以去掉？
		response.close(); // 关闭资源,可以写在finally里
		httpGet.releaseConnection(); // 释放资源
		httpClient.close(); // 关闭资源
	}
	
	
	
	
	
}
